<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title>js_for练习2</title>
    <style>
        div{
            width: 50px;
            height: 50px;
            background-color: red;
            text-align: center;
            line-height: 50px;
            color: #fff;
            position: absolute;
            top: 0px;
            left: 0px;
        }
    </style>
    <script type="text/javascript">
        window.onload=function(){
            var temp="";
            var oDiv=document.getElementsByTagName("div");
            for(var i=0;i<25;i++){
                temp+="<div>"+i+"</div>"
            }
            document.body.innerHTML=temp;
            for(var i=0;i<oDiv.length;i++){
                oDiv[i].style.left=i*50+"px";
                if(i>=(oDiv.length/2)){
                    oDiv[i].style.top=(i-(((i-oDiv.length/2)*2)+1))*50+"px";
                }else{
                    oDiv[i].style.top=i*50+"px";
                }
            }
        }

    </script>
</head>
<body>

</body>
</html>